package bsh.compilation;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import bsh.LoadedTrait;
import bsh.Prototype;

/**
 * @author takeshi
 */
public abstract class AbstractCompilationSource implements CompilationSource {

    private final String internalName;

    private final Map<String, Class<?>> fields;

    private final Map<String, Object> constants;

    private final String sourceCode;

    private final Class<?> superType;

    /**
     * @param internalName String
     * @param fields Map
     * @param constants Map
     * @param sourceCode String
     * @param superType Class
     */
    public AbstractCompilationSource(String internalName, Map<String, Class<?>> fields, Map<String, Object> constants, String sourceCode,
            Class<?> superType) {
        super();
        this.internalName = internalName;
        this.fields = fields;
        this.constants = constants;
        this.sourceCode = sourceCode;
        this.superType = superType;
    }

    /**
     * @param internalName string
     * @param fields map
     * @param constants map
     * @param sourceCode string
     */
    public AbstractCompilationSource(String internalName, Map<String, Class<?>> fields, Map<String, Object> constants, String sourceCode) {
        this(internalName, fields, constants, sourceCode, Prototype.class);
    }

    /**
     * @param internalName string
     * @param fields map
     * @param constants map
     */
    public AbstractCompilationSource(String internalName, Map<String, Class<?>> fields, Map<String, Object> constants) {
        this(internalName, fields, constants, internalName + ".bsh", Prototype.class);
    }

    /**
     * @param internalName string
     * @param sourceCode string
     */
    public AbstractCompilationSource(String internalName, String sourceCode) {
        this(internalName, new HashMap<String, Class<?>>(), new HashMap<String, Object>(), sourceCode, Prototype.class);
    }

    /**
     * {@inheritDoc}
     */
    public String internalName() {
        return this.internalName;
    }

    /**
     * {@inheritDoc}
     */
    public Map<String, Object> constants() {
        return this.constants;
    }

    /**
     * {@inheritDoc}
     */
    public Map<String, Class<?>> fieldTypes() {
        return this.fields;
    }

    /**
     * {@inheritDoc}
     */
    public String sourceCodeName() {
        return this.sourceCode;
    }

    /**
     * {@inheritDoc}
     */
    public Class<?> superType() {
        return this.superType;
    }

    /**
     * {@inheritDoc}
     */
    public String className() {
        return this.internalName().replaceAll("[/]", ".");
    }

    /**
     * {@inheritDoc}
     */
    public Map<String, Class<?>> typeAlias() {
        return new HashMap<String, Class<?>>();
    }

    /**
     * {@inheritDoc}
     */
    public List<String> wildcardImports() {
        return new ArrayList<String>();
    }

    /**
     * {@inheritDoc}
     */
    public List<Class<?>> implementedInterfaces() {
        return new ArrayList<Class<?>>();
    }

    /**
     * {@inheritDoc}
     */
    public List<LoadedTrait> implementedTraits() {
        return new ArrayList<LoadedTrait>();
    }

}
